﻿var EMAIL_REGULAR_EXPRESSION="(\\w|[-.])+@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
var PASSWORD_REGULAR_EXPRESSION="^\\w{6,12}$";
var NICKNAME_REGULAR_EXPRESSION="^[a-z0-9\\u4e00-\\u9fa5]{2,20}$";
var VERIFY_CODE_EXPRESSION="^\\d{4}$";
var NUMBER_IS_EXPRESSION="^[0-9]*$";

var MSG_NICKNAME_USED="该昵称已被注册";
var MSG_EMAIL_USED="该E-mail已被注册";
var MSG_VERIFYCODE_ERROR = "验证码不正确";
var MSG_COOKIE_DISABLED = "登录之前请您先打开浏览器的Cookie功能。";
var MSG_EMAIL_FORMAT_ERROR = "Email格式不正确";
var MSG_NICKNAME_FORMAT_ERROR = "昵称格式不正确";
var MSG_PASSWORD_FORMAT_ERROR = "密码不符合规则";
var MSG_PASSWORD_NOT_IDENTICAL ="密码不一致";
var MSG_VERIFY_CODE_FORMAT_ERROR = "四位数字";
var MSG_NUMBER_IS_FORMAT_ERROR = "请填写数字";
var MSG_PROVINCE_FORMAT_ERROR = "请选择省";
var MSG_CITY_FORMAT_ERROR = "请选择城市";

var BookDetailUrl = "http://comm.dangdang.com/bookshelf/set_inbookshelflist.aspx";

String.prototype.trim=function() 
{ 
	return this.replace(/(\s*$)|(^\s*)/g, ''); 
} 

function requireFieldValid(controlToValidID,msgSpanID,errorMessage)
{
    var objControlToValid=document.getElementById(controlToValidID);
    var objMsgSpan=document.getElementById(msgSpanID);
    var isValid=objControlToValid.value.trim()!='';
    objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid?'':errorMessage;
    return isValid;
}

function compareFieldValid(controlToValidID,compareToValidID,msgSpanID,errorMessage)
{
	var objControlToValid=document.getElementById(controlToValidID);
	var objCompareToValid=document.getElementById(compareToValidID);
	var objMsgSpan=document.getElementById(msgSpanID);
	var isValid=objControlToValid.value.trim()==objCompareToValid.value.trim();
	objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid? '' : errorMessage;
    return isValid;
}

function regularExpressionValid(controlToValidID,validationExpression,msgSpanID,errorMessage)
{
    var objRegExp = new RegExp(validationExpression,"g");
    var objControlToValid=document.getElementById(controlToValidID);
    var objMsgSpan=document.getElementById(msgSpanID);
    var isValid=objRegExp.test(objControlToValid.value);
    objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid? '' : errorMessage;
    return isValid;
}


function requireRadFieldValid(RadOne,RadTwo,msgSpanID,errorMessage)
{
    var isValid;
    var objRadOne=document.getElementById(RadOne);
    var objRadTwo=document.getElementById(RadTwo);
    var objMsgSpan=document.getElementById(msgSpanID);
    isValid=objRadOne.checked!=''||objRadTwo.checked!='';   
    objMsgSpan.style.color = "red"; 
    objMsgSpan.innerHTML=isValid?'':errorMessage;
    return isValid;
}

//判断省和城市
function requireSelectValid(controlToValidID,msgSpanID,errorMessage)
{
    var objControlToValid=document.getElementById(controlToValidID);
    var objMsgSpan=document.getElementById(msgSpanID);
    var isValid=objControlToValid.value>0;
    objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid?'':errorMessage;
    return isValid;
}

//验证是否为数字
function isNumber(oNum)
{
    if(!oNum) return false;
    var strP=/^\d+(\.\d+)?$/;
    if(!strP.test(oNum)) return false;
    try{
    if(parseFloat(oNum)!=oNum) return false;
}
catch(ex)
{
    return false;
}
    return true;
}

//检查小调查内容
function CheckResearchCont()
{
    if($("txt_Content").value=='') return false;
    var contlen = $("txt_Content").value.length;
    if(contlen>920)
    {
       $("p_result").innerHTML =  "<span class='red_purple'>限制为900字!目前字数为"+contlen+"字</span>";
       return false;
    }
    return true;
}

function openBookDetailPage(type)
{
   
    var url;
    if(type=="all")
        url =BookDetailUrl + "?stype=all";
    else
    {
        var ids = GetBookProductIds();
        if(ids=='')
        {
            alert("请您选择要导入书架的书!");
            return;
        }
        url =BookDetailUrl + "?productIds="+ids;    
    }
    window.location = url;
}

function openWin(url,name,w,h)
 {
    var x=(window.screen.width-w)/2;
	var y=(window.screen.height-h)/2;
	var win=window.open (url,name,'toolbar=0,location=0,status=0,top='+y+',left='+x+',width='+w+',height='+h );
	win.focus();
	
	return win;
 }

//获取导入选中书id
function GetBookProductIds()
{
    var retIds='';
    var objContainer=$("x");	
        var cbList = objContainer.getElementsByTagName("input");
        var cbs = $A(cbList);
        cbs.each(function(cb){        
            if(cb.getAttribute("type").toString()=='checkbox'&cb.checked!='')
            {                 			    
                retIds += cb.id.trim()+';';                
            }            
        })
    return retIds;
}

//过滤html
function ReplaceHTML(data)
{
    return data.replace(/\</g,"");    
}

function SetImage(img){ 
var width=72;
var height=97;

var image=new Image(); 
image.src=img.src;
	if(image.width>0 && image.height>0)
	{
	  if(image.width!=width)
	  {
	  	img.width=width;
	  } 
	  if(img.height!=height)
	  {
		img.height=height;
	  }
	}
	
}

function DrawImage(img){ 
var width=50;
var height=80;
//width="50px" height="69px"
var image=new Image(); 
image.src=img.src; 
	if(image.width>0 && image.height>0)
	{
	  if(image.width!=width)
	  {
	  	rate=image.height/image.width;
	  	newHeight=rate*width;
	  	img.width=width;
	  	img.height=newHeight;
	  } 
	}
	if(img.height>height)
	{
		rate=image.width/image.height;
		newWidth=rate*height;
		img.height=height;
		img.width=newWidth;
	}
}
